package kr.couponplay.android.util;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils;

public class HttpUtils {
	public static String execute(String url) throws Exception {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpParams params = httpClient.getParams();
        HttpConnectionParams.setConnectionTimeout(params, 10000);
        HttpConnectionParams.setSoTimeout(params, 10000);
        
        HttpGet method = new HttpGet(url);
        method.setHeader( "Connection", "Keep-Alive" );
        HttpResponse response = httpClient.execute(method);
        int status = response.getStatusLine().getStatusCode();
        if (status != HttpStatus.SC_OK) {
            throw new Exception( "http response status error!! status is " + status );
        }
        return EntityUtils.toString( response.getEntity(), "UTF-8" );
	}
}
